
class Solution {
    public boolean isSymmetric(TreeNode root) {
        if(root == null) {
            return true;
        }
        return isSymmetricChild(root.left,root.right);
    }
    public boolean isSymmetricChild(TreeNode leftTree,TreeNode rightTree) {
        //空树对称
        if(leftTree == null && rightTree == null) {
            return true;
        }
        //结构不相同 必定不对称
        if(leftTree != null && rightTree == null || 
        leftTree == null && rightTree != null) {
            return false;
        }
        //节点值不相同 必定不对称
        if(leftTree.val != rightTree.val) {
            return false;
        }
        //左子树的左树和右子树的右树 
        //左子树的右树和右子树的左树
        //都要对称
        return isSymmetricChild(leftTree.left,rightTree.right) 
        && isSymmetricChild(leftTree.right,rightTree.left);
    }
}

